package com.guinea.core.tag;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.guinea.core.SpringContextHolder;

import ex.system.service.DictionaryServiceEx;

public class DictionaryTag extends TagSupport {

	private static final long serialVersionUID = -774840953985543612L;

	String type;

	String var;
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	
	public int doEndTag() throws JspException {
		List dict = (List) pageContext.getServletContext().getAttribute("dict");
		DictionaryServiceEx dictionaryServiceEx = (DictionaryServiceEx)SpringContextHolder.getBean("dictionaryServiceEx");
		Object result = new ArrayList();
		if (type != null && var != null && dict != null && dict != null) {
			if(type.indexOf(",") > -1){
				result = dictionaryServiceEx.getJson(type,dict);
			}else{
				result = dictionaryServiceEx.getType(type,dict);
			}
		}
		pageContext.setAttribute(var, result);

		return super.doEndTag();
	}

}
